#include "pagefire.h"
#include "ui_pagefire.h"

PageFire::PageFire(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PageFire)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);

    m_lSHDList[0].append(ui->SHD1_1);SHD_stat_list_[0].append(0);
    m_lSHDList[0].append(ui->SHD2_1);SHD_stat_list_[0].append(0);
    m_lSHDList[0].append(ui->SHD3_1);SHD_stat_list_[0].append(0);
    m_lSHDList[0].append(ui->SHD4_1);SHD_stat_list_[0].append(0);
    m_lSHDList[0].append(ui->SHD5_1);SHD_stat_list_[0].append(0);
    m_lSHDList[0].append(ui->SHD6_1);SHD_stat_list_[0].append(0);
    m_lSHDList[0].append(ui->SHD7_1);SHD_stat_list_[0].append(0);

    m_lSHDList[1].append(ui->SHD1_2);SHD_stat_list_[1].append(0);
    m_lSHDList[1].append(ui->SHD2_2);SHD_stat_list_[1].append(0);
    m_lSHDList[1].append(ui->SHD3_2);SHD_stat_list_[1].append(0);
    m_lSHDList[1].append(ui->SHD4_2);SHD_stat_list_[1].append(0);

    m_lSHDList[2].append(ui->SHD1_3);SHD_stat_list_[2].append(0);
    m_lSHDList[2].append(ui->SHD2_3);SHD_stat_list_[2].append(0);
    m_lSHDList[2].append(ui->SHD3_3);SHD_stat_list_[2].append(0);
    m_lSHDList[2].append(ui->SHD4_3);SHD_stat_list_[2].append(0);

    m_lSHDList[3].append(ui->SHD1_4);SHD_stat_list_[3].append(0);
    m_lSHDList[3].append(ui->SHD2_4);SHD_stat_list_[3].append(0);
    m_lSHDList[3].append(ui->SHD3_4);SHD_stat_list_[3].append(0);
    m_lSHDList[3].append(ui->SHD4_4);SHD_stat_list_[3].append(0);

    m_lSHDList[4].append(ui->SHD1_5);SHD_stat_list_[4].append(0);
    m_lSHDList[4].append(ui->SHD2_5);SHD_stat_list_[4].append(0);
    m_lSHDList[4].append(ui->SHD3_5);SHD_stat_list_[4].append(0);
    m_lSHDList[4].append(ui->SHD4_5);SHD_stat_list_[4].append(0);

    m_lSHDList[5].append(ui->SHD1_6);SHD_stat_list_[5].append(0);
    m_lSHDList[5].append(ui->SHD2_6);SHD_stat_list_[5].append(0);
    m_lSHDList[5].append(ui->SHD3_6);SHD_stat_list_[5].append(0);
    m_lSHDList[5].append(ui->SHD4_6);SHD_stat_list_[5].append(0);
    m_lSHDList[5].append(ui->SHD5_6);SHD_stat_list_[5].append(0);
    m_lSHDList[5].append(ui->SHD6_6);SHD_stat_list_[5].append(0);
    m_lSHDList[5].append(ui->SHD7_6);SHD_stat_list_[5].append(0);

    m_lLHDList[0].append(ui->LHD1_1);LHD_stat_list_[0].append(0);
    m_lLHDList[0].append(ui->LHD2_1);LHD_stat_list_[0].append(0);
    m_lLHDList[0].append(ui->LHD3_1);LHD_stat_list_[0].append(0);
    m_lLHDList[0].append(ui->LHD4_1);LHD_stat_list_[0].append(0);

    m_lLHDList[1].append(ui->LHD1_2);LHD_stat_list_[1].append(0);
    m_lLHDList[1].append(ui->LHD2_2);LHD_stat_list_[1].append(0);
    m_lLHDList[1].append(ui->LHD3_2);LHD_stat_list_[1].append(0);

    m_lLHDList[2].append(ui->LHD1_3);LHD_stat_list_[2].append(0);
    m_lLHDList[2].append(ui->LHD2_3);LHD_stat_list_[2].append(0);
    m_lLHDList[2].append(ui->LHD3_3);LHD_stat_list_[2].append(0);

    m_lLHDList[3].append(ui->LHD1_4);LHD_stat_list_[3].append(0);
    m_lLHDList[3].append(ui->LHD2_4);LHD_stat_list_[3].append(0);
    m_lLHDList[3].append(ui->LHD3_4);LHD_stat_list_[3].append(0);

    m_lLHDList[4].append(ui->LHD1_5);LHD_stat_list_[4].append(0);
    m_lLHDList[4].append(ui->LHD2_5);LHD_stat_list_[4].append(0);
    m_lLHDList[4].append(ui->LHD3_5);LHD_stat_list_[4].append(0);

    m_lLHDList[5].append(ui->LHD1_6);LHD_stat_list_[5].append(0);
    m_lLHDList[5].append(ui->LHD2_6);LHD_stat_list_[5].append(0);
    m_lLHDList[5].append(ui->LHD3_6);LHD_stat_list_[5].append(0);
    m_lLHDList[5].append(ui->LHD4_6);LHD_stat_list_[5].append(0);
}

PageFire::~PageFire()
{
    delete ui;
}

void PageFire::setResetBtnVisible(bool xVisible)
{
    ui->Btn_ResetFire->setVisible(xVisible);
}

void PageFire::setSHDStat(uint8_t car, uint8_t index, uint8_t stat)
{
    if(car >= 6 || index >= m_lSHDList[car].length())
        return;
    SHD_stat_list_[car][index] = stat;
    switch (stat) {
    case 0:
        m_lSHDList[car][index]->setStyleSheet("border-image: url(:/Images/Unknow.png);");
        break;
    case 2:
        m_lSHDList[car][index]->setStyleSheet("border-image: url(:/Images/FireDetect.png);");
        break;
    case 1:
        m_lSHDList[car][index]->setStyleSheet("border-image: url(:/Images/SHDFlt.png);");
        break;
    case 4:
        m_lSHDList[car][index]->setStyleSheet("border-image: url(:/Images/SHDDirty.png);");
        break;
    case 3:
        m_lSHDList[car][index]->setStyleSheet("border-image: url(:/Images/SHDIso.png);");
        break;
    case 5:
        m_lSHDList[car][index]->setStyleSheet("border-image: url(:/Images/SHDOK.png);");
        break;
    default:
        m_lSHDList[car][index]->setStyleSheet("border-image: url(:/Images/Unknow.png);");
        break;
    }
}

void PageFire::setLHDStat(uint8_t car,uint8_t index, uint8_t stat)
{
    if(car >= 6 || index >= m_lLHDList[car].length())
        return;
    LHD_stat_list_[car][index] = stat;
    switch (stat) {
    case 0:
        m_lLHDList[car][index]->setStyleSheet("border-image: url(:/Images/Unknow.png);");
        break;
    case 2:
        m_lLHDList[car][index]->setStyleSheet("border-image: url(:/Images/FireDetect.png);");
        break;
    case 1:
        m_lLHDList[car][index]->setStyleSheet("border-image: url(:/Images/LHDFlt.png);");
        break;
    case 3:
        m_lLHDList[car][index]->setStyleSheet("border-image: url(:/Images/LHDOK.png);");
        break;
    default:
        m_lLHDList[car][index]->setStyleSheet("border-image: url(:/Images/Unknow.png);");
        break;
    }
}

void PageFire::on_Btn_ResetFire_clicked()
{
    emit signal_ResetFireAlarm(true);
    ui->Btn_ResetFire->setEnabled(false);
    QTimer::singleShot(3000,this,[=](){
        emit signal_ResetFireAlarm(false);
        ui->Btn_ResetFire->setEnabled(true);
    });
}

void PageFire::updateResetBtnVisibleStat()
{
    for(int i=0;i<6;i++)
    {
        if(SHD_stat_list_[i].contains(2))
        {
            setResetBtnVisible(true);
            return;
        }
        if(LHD_stat_list_[i].contains(2))
        {
            setResetBtnVisible(true);
            return;
        }
    }
    setResetBtnVisible(false);
}
